package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.dto.BmiDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    @GetMapping ("/v1/bmi/add")//http://localhost:8080/v1/bmi/add?weight=54&height=1.64
    @ResponseBody
    //计算公式bmi=weight/height^2
    public String bmi(BmiDTO bmiDTO) {
        System.out.println("bmiDTO="+bmiDTO);
        double height = bmiDTO.getHeight();
        double weight = bmiDTO.getWeight();
        double v = weight / (height * height);

        if (v < 18.5) {
            return "偏瘦";
        } else if (v < 24) {
            return "正常";
        } else if (v < 27) {
            return "微胖";
        } else {
            return "胖";
        }

    }
    @GetMapping ("/v2/bmi/add/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height, @PathVariable Double weight) {
        double v = weight / (height * height);

        if (v < 18.5) {
            return "偏瘦";
        } else if (v < 24) {
            return "正常";
        } else if (v < 27) {
            return "微胖";
        } else {
            return "胖";
        }
    }
}

